package com.mall.api.controller;

import com.mall.api.common.returnData.R;
import com.mall.api.common.returnData.ReturnIndex;
import com.mall.api.entity.ProductCategoryEntity;
import com.mall.api.service.AppBannerService;
import com.mall.api.service.AppNavigationService;
import com.mall.api.service.ProductCategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@Api(tags = "app首页接口")
@RestController
@RequestMapping(value = "/Index")
public class IndexController {

    // banner 轮播图
    @Autowired
    private AppBannerService appBannerService;

    // 首页导航
    @Autowired
    private AppNavigationService appNavigationService;

    // 商品分类
    @Autowired
    private ProductCategoryService productCategoryService;

    @ApiOperation("首页Index")
    @RequestMapping(value = "/IndexList", method = RequestMethod.GET)
    public R IndexList(HttpServletRequest request, HttpServletResponse response){
        response.setHeader("Access-Control-Allow-Origin", "*");
        response.setHeader("Access-Control-Allow-Headers", "X-Requested-With,Content-Type,Content-Length");
        response.setHeader("Content-Type", "text/html;charset=UTF-8");
        ReturnIndex returnIndex = new ReturnIndex();
        // 轮播图
        returnIndex.setBannerList(appBannerService.getAppBannerList());
        // 品牌列表
        returnIndex.setBrandInfoList(null);
        // 首页导航
        returnIndex.setAppNavigationList(appNavigationService.getAppNavigationList());
        // 商品分类
        List<ProductCategoryEntity> productCategoryList = productCategoryService.getProductCategoryList();
        returnIndex.setProductCategoryList(productCategoryList);

        return R.ok().put("data",returnIndex);
    }
}
